package org.yoki.tool.core.exception;


import org.yoki.tool.core.exception.enums.BasicExceptionStatus;

/**
 * Created by SunnyWen on 2017/6/8.
 */
public class ParamNullValueException extends BasicException {

    private BasicExceptionStatus status = BasicExceptionStatus.paramNullValue;

    public ParamNullValueException() {
        super(BasicExceptionStatus.paramNullValue.getCode(), BasicExceptionStatus.paramNullValue.getMsg());
    }

    public ParamNullValueException(String paramName) {
        super(BasicExceptionStatus.paramNullValue.getCode(), "所需参数:" + paramName + "为空！");
    }

    public static void validateParam(Object paramValue) throws BasicException {
        validateParam(paramValue, null);
    }

    public static void validateParam(Object paramValue, String paramName) throws BasicException {
        ParamNullValueException e = null;
        boolean flag = false;
        if (null == paramValue) {
            flag = true;
        }
        if (paramValue instanceof String) {
            if ("".equals(paramValue))
                flag = true;
        }
        if (flag) {
            if (null != paramName && !"".equals(paramName))
                e = new ParamNullValueException(paramName);
            else
                e = new ParamNullValueException();
            throw e;
        }
    }


}
